package com.example.xiongan_app_yy.utils;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.util.Log;
import android.view.DisplayCutout;
import android.view.View;

import java.util.List;

/**
 * @ProjectName: WMS
 * @Package: com.zada.wms.utils
 * @ClassName: StatusBarUtil
 * @Description: 描述：获取状态栏高度，以及谷歌官方获取刘海屏api
 * @Author: 吴航
 * @CreateDate: 2019/7/23 9:09
 * @UpdateUser: 更新者：
 * @UpdateDate: 2019/7/23 9:09
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class StatusBarUtil {

    //暂不提供，只供log
    @TargetApi(28)
    public static void getNotchParams(Activity activity) {
        final View decorView = activity.getWindow().getDecorView();

        decorView.post(new Runnable() {
            @Override
            public void run() {
                DisplayCutout displayCutout = decorView.getRootWindowInsets().getDisplayCutout();
                Log.e("TAG", "安全区域距离屏幕左边的距离 SafeInsetLeft:" + displayCutout.getSafeInsetLeft());
                Log.e("TAG", "安全区域距离屏幕右部的距离 SafeInsetRight:" + displayCutout.getSafeInsetRight());
                Log.e("TAG", "安全区域距离屏幕顶部的距离 SafeInsetTop:" + displayCutout.getSafeInsetTop());
                Log.e("TAG", "安全区域距离屏幕底部的距离 SafeInsetBottom:" + displayCutout.getSafeInsetBottom());

                List<Rect> rects = displayCutout.getBoundingRects();
                if (rects == null || rects.size() == 0) {
                    Log.e("TAG", "不是刘海屏");
                } else {
                    Log.e("TAG", "刘海屏数量:" + rects.size());
                    for (Rect rect : rects) {
                        Log.e("TAG", "刘海屏区域：" + rect);
                    }
                }
            }
        });
    }

    public static int getStatusBarHeight(Context context) {
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
        int height = resources.getDimensionPixelSize(resourceId);
        Log.e("TAG", "状态栏高度" + height);
        return height;
    }
}
